package net.easyjava.base.constants;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wenxiaoning on 15/12/27.
 */
public enum  AlbumConstants {

    DATASOURCE(1,0,"数据库",1),
    DATASOURCE_MONGODB(2,1,"MongoDB",1),
    DATASOURCE_MYSQL(3,1,"Mysql",2),
    DATASOURCE_REDIS(4,1,"Redis",3),

    SERVER(5,0,"服务器",2),
    SERVER_RESIN(6,5,"Resin",1),
    SERVER_NGINX(7,5,"Nginx",2),
    SERVER_JETTY(8,5,"Jetty",3),

    ;

    private AlbumConstants(int id, int fatherId, String name, int displayOrder) {
        this.id = id;
        this.fatherId = fatherId;
        this.name = name;
        this.displayOrder = displayOrder;
    }

    private int id;
    private int fatherId;
    private String name;
    private int displayOrder;
    private List<AlbumConstants> subAlbums;

    public int getId() {
        return id;
    }

    public int getFatherId() {
        return fatherId;
    }

    public String getName() {
        return name;
    }

    public int getDisplayOrder() {
        return displayOrder;
    }

    public List<AlbumConstants> getSubAlbums() {
        return subAlbums;
    }

    public void setSubAlbums(List<AlbumConstants> subAlbums) {
        this.subAlbums = subAlbums;
    }

    /**
     * 获取级联菜单
     * @param fatherId
     * @return
     */
    public static List<AlbumConstants> getList(int fatherId){
        AlbumConstants[] AlbumConstantses =  AlbumConstants.values();
        List<AlbumConstants> AlbumConstantsList = new ArrayList<AlbumConstants>();
        for (AlbumConstants AlbumConstants:AlbumConstantses){
            if(AlbumConstants.getFatherId() ==fatherId){
                if(fatherId ==0){
                    //获取子菜单
                    AlbumConstants.setSubAlbums(getList(AlbumConstants.getId()));
                }
                //添加
                AlbumConstantsList.add(AlbumConstants);
            }
        }
        return AlbumConstantsList;
    }

    public static void main(String[] args) {

    }
}
